package cn.le.beans.dto;

import cn.hutool.core.date.DateUtil;
import cn.le.utils.SqlUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description
 * @Author le
 * @Date 2020/2/26 15:41
 * @Version 0.1
 **/
@Data
@ApiModel("爬虫房源搜索")
public class CrawlerHomeSearchDto extends BasePage{

    @ApiModelProperty(value = "标题")
    private String title;

    @ApiModelProperty(value = "起拍价")
    private String initialPrice;

    @ApiModelProperty(value = "围观人数")
    private String viewerCount;

    @ApiModelProperty(value = "报名人数")
    private String bidCount;

    @ApiModelProperty(value = "开拍时间")
    private Date startDate;

    @ApiModelProperty(value = "新增日期")
    private Date createDate;

    @ApiModelProperty(value = "拍卖类型")
    private String sellOff;

    @ApiModelProperty(value = "状态")
    private String status;

    public String getStatus(){
        return SqlUtils.like("status",status);
    }

    public String getSellOff(){
        return SqlUtils.like("sell_off",sellOff);
    }

    public String getCreateDate(){
        if (createDate == null){
            return "";
        }
        StringBuilder sb = new StringBuilder();
        sb.append(" and create_date >= '").append(DateUtil.format(createDate, "yyyy-MM-dd")).append("'");
        return sb.toString();
    }

    public String getStartDate(){
        if (startDate == null){
            return "";
        }
        StringBuilder sb = new StringBuilder();
        sb.append(" and start > '").append(DateUtil.format(startDate, "yyyy-MM-dd")).append("'");
        return sb.toString();
    }

    public String getBidCount(){
        return SqlUtils.equivalent("bid_count",bidCount);
    }

    public String getViewerCount(){
        return SqlUtils.equivalent("viewer_count",viewerCount);
    }

    public String getInitialPrice(){
        return SqlUtils.equivalent("initial_price",initialPrice);
    }

    public String getTitle(){
        if (StringUtils.isEmpty(title)){
            return "";
        }
        int index = title.indexOf(",not(");
        String sql = "";
        if (index > 0){
            String not = title.substring(index + 5,title.length() - 1);
            sql = SqlUtils.notLike("title",not);
            sql = sql + SqlUtils.like("title",title.substring(0,index));
        }else {
            sql = SqlUtils.like("title",title);
        }
        return sql;
    }
}
